package game_elements_layer.guys_stuff.guys_actions;

import game_elements_layer.guys_stuff.Guys;
import game_elements_layer.productions_stuff.Productions;
import game_elements_layer.resourses_stuff.Money;
import game_elements_layer.resourses_stuff.Resources;


/**
 * Created with IntelliJ IDEA.
 * User: Slava
 * Date: 06.10.14
 * Time: 21:28
 * To change this template use File | Settings | File Templates.
 */
public class GuysCreateProductionAction extends GuysActions {

    Guys guy;
    int creationTime;
    int cost;
    Resources resourceType;

    public GuysCreateProductionAction(Guys guy, int creationTime, int cost, Resources resourceType) throws NotEnoughMoneyException {
        if (cost>guy.getGuysOwner().getMoney().getAmount())
            throw new NotEnoughMoneyException(guy.getGuysOwner()+" have not enough money to create production now");
        this.guy = guy;
        this.creationTime = creationTime;
        this.resourceType = resourceType;
        this.cost = cost;
    }

    @Override
    public void perform() {
        Productions newProduction = new Productions(creationTime, guy.getGuysOwner(), new Money(cost), resourceType, guy.getCurrentLocation());
        guy.getCurrentLocation().setContainedProduction(newProduction);
        guy.getGuysOwner().payMoney(cost);
        guy.getGuysOwner().getProductions().add(newProduction);
    }
}
